﻿using Microsoft.AspNetCore.Mvc;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using System;
using WMS.BasicData.Clients;
using WMS.StorageManagement.DTO;
using WMS.BasicData.Vendors;
using WMS.StorageManagement.BinLocationDefinitions;
using WMS.StorageManagement.BinLocationDefinitions.DTO;

namespace WMS.Web.Controllers.StorageManagement.BinLocationDefinitions
{
    /// <summary>
    /// 可用储位控制器
    /// </summary>
    public class BinLocationDefinitionController : Controller
    {

        /// <summary>
        /// 供应商接口
        /// </summary>
        private readonly IBinLocationDefinitionAppService _binLocationDefinitionAppService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public BinLocationDefinitionController(IBinLocationDefinitionAppService binLocationDefinitionAppService)
        {
            _binLocationDefinitionAppService = binLocationDefinitionAppService;
        }

        #region 视图

        public IActionResult Index()
        {
            return View();
        }


        /// <summary>
        /// 库位定义视图
        /// </summary>
        /// <returns></returns>
        public IActionResult LocationDefiView()
        {
            return View();
        }

        /// <summary>
        /// 库位定义添加视图
        /// </summary>
        /// <returns></returns>
        public IActionResult CreateLocationDefi()
        {
            return View();
        }

        /// <summary>
        /// 库位定义编辑视图
        /// </summary>
        /// <returns></returns>
        public IActionResult EditLocationDefi()
        {
            ViewBag.id = Request.Query["id"].ToString();
            return View();
        }

        #endregion



        #region 控制器

        /// <summary>
        /// 可用储位
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetEmptySpace(int page, int limit, string? customer)
        {
            var getEmptySpace = await _binLocationDefinitionAppService.GetEmptySpace(page, limit, customer);
            return Json(new { data = getEmptySpace.Queryable, code = 0, count = getEmptySpace.RowCount });
        }

        /// <summary>
        /// 可用储位
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetClient()
        {
            var getClient = await _binLocationDefinitionAppService.GetClient();
            return Json(new { data = getClient });
        }

        /// <summary>
        /// 创建储位定义
        /// </summary>
        /// <param name="CreateBinDTO"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<int> CreateBinLocationDefi(BinLocationDefiDTO createBinDTO)
        {
           int result=await _binLocationDefinitionAppService.CreateBinLocationDefi(createBinDTO);
            return result;
        }

        /// <summary>
        /// 删除储位定义
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<int> DeleteBinLocationDefi(int id)
        {
           var result=await _binLocationDefinitionAppService.DeleteBinLocationDefi(id);
            return result;
        }

        /// <summary>
        /// 获取储位编号获取库位定义信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        /// <exception cref="NotImplementedException"></exception>
        public async Task<BinLocationDefiDTO> GetBinLocationDefiById(int id)
        {
           var result=await _binLocationDefinitionAppService.GetBinLocationDefiById(id);
            return result;
        }

        /// <summary>
        /// 修改储位定义列表
        /// </summary>
        /// <param name="updateBinDTO"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<int> UpdateBinLocationDefi(BinLocationDefiDTO updateBinDTO)
        {
           int result=await _binLocationDefinitionAppService.UpdateBinLocationDefi(updateBinDTO);
            return result;
        }

        #endregion

    }
}
